package czopyk.model.cost;

import java.util.HashMap;
import java.util.Map;

import pl.czopyk.colt.math.DistributionWrapper;

public class DistributionManager {
	
	private Map<DistributionId, DistributionWrapper> idToDistribution = new HashMap<DistributionId, DistributionWrapper>();
	
	public double getDistributionDoubleValue(DistributionId id) {
		DistributionWrapper distributionWrapper = idToDistribution.get(id);
		if (distributionWrapper == null) {
			throw new IllegalStateException(
					"No distribution defined for id = " + id.getValue());
		}
		double d = distributionWrapper.nextDouble();
		if (Double.isNaN(d)) {
			throw new IllegalStateException("Nan obtained from distribution '" + id + "'");
		}
		return d;
	}

	public int getDistributionIntValue(DistributionId id) {
		return idToDistribution.get(id).nextInt();
	}

	public DistributionWrapper getDistributionById(DistributionId id) {
		return idToDistribution.get(id);
	}
	
	public void registerDistribution(String id, DistributionWrapper ad) {
		idToDistribution.put(new DistributionId(id), ad);
	}

}
